/*****************************************************************************
 * logic.c: Copyright 2025 (c) CoreLink
 * Desc:
 *
 * Author: Flying (weekend@111.com)
 * Date: 2025-09-25 12:03:00
 * Notes:
 *
 * ---------------------------------------------------------------------------
 * LastEditors:
 * LastEditTime:
 *****************************************************************************/
/*------------------------------- Includes ----------------------------------*/
#include "logic.h"
#include "ai_audio.h"
#include "media_src_zh.h"
#include "tal_api.h"
#include "tal_log.h"

/*------------------- 全局定义和声明 -------------------*/

/*---------------------- 常量/宏定义 -----------------------*/

/*----------------------- 类型声明 ---------------------------------*/

/*----------------------- 变量声明 -----------------------------*/

/*----------------------- 函数原型 --------------------------------*/
static void __app_ai_audio_state_inform_cb(AI_AUDIO_STATE_E state);
static void __app_ai_audio_evt_inform_cb(AI_AUDIO_EVENT_E event, uint8_t *data, uint32_t len, void *arg);
/*----------------------- 功能实现 --------------------------------*/
void logic_init(void)
{
    OPERATE_RET rt = OPRT_OK;
    AI_AUDIO_CONFIG_T ai_audio_cfg;
    ai_audio_cfg.work_mode = AI_AUDIO_MODE_MANUAL_SINGLE_TALK;
    ai_audio_cfg.evt_inform_cb = __app_ai_audio_evt_inform_cb;
    ai_audio_cfg.state_inform_cb = __app_ai_audio_state_inform_cb;

    TUYA_CALL_ERR_LOG(ai_audio_init(&ai_audio_cfg));
}

static void __app_ai_audio_evt_inform_cb(AI_AUDIO_EVENT_E event, uint8_t *data, uint32_t len, void *arg)
{
    switch (event)
    {
    case AI_AUDIO_EVT_HUMAN_ASR_TEXT:
    {
        PR_DEBUG("---> AI_AUDIO_EVT_HUMAN_ASR_TEXT");

        if (len > 0 && data)
        {
            PR_DEBUG("data len:%d , data[%s]", len, data);
        }
    }
    break;
    case AI_AUDIO_EVT_AI_REPLIES_TEXT_START:
    {
        PR_DEBUG("---> AI_AUDIO_EVT_AI_REPLIES_TEXT_START");

        if (len > 0 && data)
        {
            PR_DEBUG("data len:%d , data[%s]", len, data);
        }
    }
    break;
    case AI_AUDIO_EVT_AI_REPLIES_TEXT_DATA:
    {
        PR_DEBUG("---> AI_AUDIO_EVT_AI_REPLIES_TEXT_DATA");

        if (len > 0 && data)
        {
            PR_DEBUG("data len:%d , data[%s]", len, data);
        }
    }
    break;
    case AI_AUDIO_EVT_AI_REPLIES_TEXT_END:
    {
        PR_DEBUG("---> AI_AUDIO_EVT_AI_REPLIES_TEXT_END");

        if (len > 0 && data)
        {
            PR_DEBUG("data len:%d , data[%s]", len, data);
        }
    }
    break;
    case AI_AUDIO_EVT_AI_REPLIES_TEXT_INTERUPT:
    {
        PR_DEBUG("---> AI_AUDIO_EVT_AI_REPLIES_TEXT_END");
        if (len > 0 && data)
        {
            PR_DEBUG("data len:%d , data[%s]", len, data);
        }
    }
    break;
    case AI_AUDIO_EVT_AI_REPLIES_EMO:
    {
        AI_AUDIO_EMOTION_T *emo;
        PR_DEBUG("---> AI_AUDIO_EVT_AI_REPLIES_TEXT_END");
        emo = (AI_AUDIO_EMOTION_T *)data;
        if (emo)
        {
            if (emo->name)
            {
                PR_DEBUG("emotion name:%s", emo->name);
            }

            if (emo->text)
            {
                PR_DEBUG("emotion text:%s", emo->text);
            }
        }
    }
    break;
    case AI_AUDIO_EVT_ASR_WAKEUP:
    {
        PR_DEBUG("---> AI_AUDIO_EVT_AI_REPLIES_TEXT_END");
    }
    break;

    default:
        PR_DEBUG("other event :%d", event);

        break;
    }

    return;
}

static void __app_ai_audio_state_inform_cb(AI_AUDIO_STATE_E state)
{

    PR_DEBUG("ai audio state: %d", state);

    switch (state)
    {
    case AI_AUDIO_STATE_STANDBY:
        PR_DEBUG("---> AI_AUDIO_STATE_STANDBY");

        break;
    case AI_AUDIO_STATE_LISTEN:
        PR_DEBUG("---> AI_AUDIO_STATE_LISTEN");
        break;
    case AI_AUDIO_STATE_UPLOAD:
        PR_DEBUG("---> AI_AUDIO_STATE_UPLOAD");
        break;
        break;
    case AI_AUDIO_STATE_AI_SPEAK:
        PR_DEBUG("---> AI_AUDIO_STATE_AI_SPEAK");
        break;

    default:
        break;
    }
}

/*---------------------------------------------------------------------------*/